﻿using System;
using System.Collections.Generic;

namespace Kratos.Framework.ContentManagement.Models.SystemRights
{
    /// <summary>
    /// 被维护的权限
    /// </summary>
    public class ActionPermission
    {
        public ActionPermission()
        {
            _users = new List<UserInfo>();
            _groups = new List<Group>();
        }

        public virtual int Id { get; set; }

        public virtual string ActionName { get; set; }

        public virtual string ControllerName { get; set; }

        public virtual string ActionDescription { get; set; }

        public virtual string ControllerDescription { get; set; }

        public virtual Guid Guid { get; set; }

        /// <summary>
        /// 数据库中是否存在
        /// </summary>
        public virtual bool IsExist { get; set; }

        private IList<UserInfo> _users;
        public virtual IList<UserInfo> Users
        {
            get { return _users; }
            set { _users = value; }
        }

        private IList<Group> _groups;
        public virtual IList<Group> Groups
        {
            get { return _groups; }
            set { _groups = value; }
        }

        #region 共有方法
        public virtual void AddUser(UserInfo user)
        {
            user.AddActionPermission(this);
            _users.Add(user);
        }

        public virtual void AddGroup(Group group)
        {
            //group.AddActionPermission(this);
            _groups.Add(group);
        }
        #endregion
    }
}
